﻿<link href="/UI/css/components/components.min.css" rel="stylesheet" />
<link href="/UI/fonts-m/soicon-m.min.css" rel="stylesheet" />

<!--时间线组件-->
<template>
    <ul class="v-time-line">
        <li v-for="i in Logs" key="idstr">
            <div class="vtl-head">
                <i :class="i.icon||'soicon icon-date'"></i>
                <span class="vtl-node"></span>
                <div class="vtl-time">
                    <label>{{i.createtime.formate('yyyy-MM-dd')}}</label>
                    <label>{{i.createtime.formate('HH:mm:ss')}}</label>
                </div>
            </div>
            <div class="vtl-body" v-if="!template">
                <span class="vtl-ttl">{{i.title}}</span>
                <br />
                <span class="vtl-con" v-if="i.company_name"><i class="soicon icon-office"></i> {{i.company_name}}</span>
                <br />
                <span class="vtl-opr"><i class="soicon icon-account"></i> {{i.oprname}} | {{i.opr_mphone||'-'}}</span>
            </div>
            <div class="vtl-body" v-else>
                <span class="vtl-ttl">{{i.title}}</span>
                <br />
                <item-render v-once :obj="i"></item-render>
                <span class="vtl-con" v-if="i.company_name"><i class="soicon icon-office"></i> {{i.company_name}}</span>
                <br />
                <span class="vtl-opr"><i class="soicon icon-account"></i> {{i.oprname}} | {{i.opr_mphone||'-'}}</span>
            </div>
        </li>
    </ul>
</template>
<script>
    vm = {
        created: function () {
            if(this.$props.template){
                var tr = Vue.extend({
                    props: ['obj'],
                    template: this.$props.template
                });
                this.$options.components["item-render"] = tr;
            }
        },
        props: {
            objid: {
                type: String,
                default:''
            },
            refobjid:{
                type: String,
                default:''
            },
            biztype: {
                type: String,
                default:""
            },
            template: {
                type: String,
                default:''
            }
        },
        data: function () {
            var opt = {
                lastId: -1,
                Logs: []
            };
            if (this.objid.length>2||this.refobjid.length>2) {
                this.load();
            }
            return opt;
        },
        watch: {
            'objid': function () {
                if (this.objid.length > 2 || this.refobjid.length > 2) {
                    this.load();
                }
            }
        },
        methods: {
            load: function () {
                var v = this;
                if (v.objid.length > 2 || v.refobjid.length > 2) {
                    $$.GetJSON("/SoBiz/GetObjLogs", { objid: v.objid, refobjid: v.refobjid, lastid: v.lastId }, function (rtn) {
                        if (rtn.IsPositive) {
                            v.lastId = rtn.Data.Logs.length > 0 ? rtn.Data.Logs[0]["idstr"].toString() : v.lastId;
                            rtn.Data.Logs.forEach(function (l) {
                                v.formate(l);
                                v.Logs.push(l);
                            });
                        }
                    });
                }
                
            },
            formate: function (x) {
                x.opr_headimg = x.opr_headimg || '/ui/imgs/default-user-headimg.jpg';
                x.memo = JSON.parse(x.memo);
                switch (this.biztype) {
                    case "MaterialTrade":
                        switch (x.action) {
                            case "PublishOrder":
                                x.title = '发布订单';
                                x.icon = 'soicon icon-send';
                                break;
                            case "RepublishOrder":
                                x.title = '变更订单';
                                x.icon = 'soicon icon-edit';
                                break;
                            case "CloseTrade":
                                x.title = '关闭订单';
                                x.icon = 'soicon icon-remove';
                                break;
                            case "RenewOrder":
                                x.title = '重新激活';
                                x.icon = 'soicon icon-edit';
                                break;
                            case "ConfirmOrder":
                                x.title = '确认订单';
                                x.icon = 'soicon-m icon-confirm';
                                break;
                            case "AbortDelivery":
                                x.title = '作废送货单';
                                x.icon = 'soicon icon-edit';
                                break;
                            case "DoDelivery":
                                x.title = '发货';
                                x.icon = 'soicon-m icon-dlv-bill';
                                break;
                            case "DoReceipt":
                                x.title = '收货确认';
                                x.icon = 'soicon-m icon-receipt';
                                break;
                            case "DoStockIn":
                                x.title = '入库同步';
                                x.icon = 'soicon icon-allinclusive';
                                break;
                            case "IgnoreDoStockIn":
                                x.title = '忽略入库同步';
                                x.icon = 'soicon-m icon-remove-outline';
                                break;
                            case "ApproveTradeReceipt":
                                x.title = "收货审核";
                                x.icon = 'soicon icon-fangdajing';
                                break;
                            case "StockInUpdated":
                                x.title = '入库状态更新';
                                x.icon = 'soicon icon-refresh';
                                break;
                            case "DoPayPlan":
                                x.title = '申请付款';
                                x.icon = 'soicon icon-edit';
                                break;
                            case "DoPay":
                                x.title = '实付登记';
                                x.icon = 'soicon icon-edit';
                                break;
                            case "AppendOrderAttachment":
                                if (x.app == 'PurchaseApp') {
                                    x.title = "上传采购合同";
                                    x.company_name = x.company_name ? x.company_name : '采购方';
                                }
                                else {
                                    x.title = "上传销售合同";
                                    x.company_name = x.company_name ? x.company_name : '供应商';
                                }
                                x.oprname&&x.oprname.length>1 ? x.oprname : 'by数据接口';
                                x.icon = 'soicon icon-attachment';
                                break;
                            default:
                                x.title = x.action;
                                x.icon = 'soicon icon-help-outline';
                                break;
                        }
                        break;
                };
                x.createtime = new Date(x.createtime);
            }
        }
    }
</script>